package yunhe.servlet;
import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import yunhe.biz.ReceiptBiz;
import yunhe.entity.Sale;
import yunhe.entity.SaleAppend;

@WebServlet(name="saleDetailsServlet",urlPatterns="/saleDetailsServlet")
public class saleDetailsServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
			String salesId = request.getParameter("ID");
			ReceiptBiz receiptbiz = new ReceiptBiz();
			Sale sale = receiptbiz.checkSaleById(salesId);
			List<SaleAppend> append = receiptbiz.checkSaleAppendById(salesId);
			HttpSession session = request.getSession();
			if(sale!=null){
				session.setAttribute("append", append);
				session.setAttribute("sale", sale);
				request.getRequestDispatcher("receipt/saleDetails.jsp").forward(request, response);
			}else{
				response.sendRedirect("receipt/checkSale.jsp");
			}
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
